package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	DepartmentEventNew           = "wms.DepartmentNew"
	DepartmentEventBeforeCreate  = "wms.DepartmentBeforeCreate"
	DepartmentEventBeforeUpdate  = "wms.DepartmentBeforeUpdate"
	DepartmentEventBeforeSave    = "wms.DepartmentBeforeCreate wms.DepartmentBeforeUpdate"
	DepartmentEventAfterCreate   = "wms.DepartmentAfterCreate"
	DepartmentEventAfterUpdate   = "wms.DepartmentAfterUpdate"
	DepartmentEventAfterSave     = "wms.DepartmentAfterCreate wms.DepartmentAfterUpdate"
	DepartmentEventDelete        = "wms.DepartmentDelete"
	DepartmentAccessControlEvent = "wms.DepartmentAccessControl"
)

func GetDepartmentConfig() *mgo.DocConfig {
	return Department_Config
}

var Department_Config *mgo.DocConfig

func init() {
	Department_Config = NewDepartmentConfig()
}
func NewDepartmentConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "wms.Department",
		Fields: []string{
			"name", "sort", "l", "r", "level", "link", "parent", "children",
		},
		RelationFields: []string{
			"parent", "children",
		},
		RelationConfigs: map[string]*mgo.DocRelation{
			"parent": {
				Config:     GetDepartmentConfig,
				DocName:    "Department",
				JoinType:   "O",
				KeyInside:  "parentId",
				KeyOutSide: "id",
			},
			"children": {
				Config:     GetDepartmentConfig,
				DocName:    "Department",
				JoinType:   "M",
				KeyInside:  "id",
				KeyOutSide: "parentId",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
